﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LsKeyboardCore
{
    public class Win32Api
    {

        /// <summary>
        /// 键盘事件
        /// </summary>
        [DllImport("user32.dll")]
        public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
        [DllImport("user32.dll")]
        public static extern byte MapVirtualKey(byte wCode, int wMap);


        [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "GetKeyState")]
        public static extern int GetKeyState(int nVirtKey); 
        public static bool GetKeyState(System.Windows.Forms.Keys keys)
        {
            return ((GetKeyState((int)keys) & 0x8000) != 0) ? true : false;
        }

        public static bool GetKeyStateEx(int nVirtKey)
        {
            return ((GetKeyState(nVirtKey) & 0x8000) != 0) ? true : false;
        }


        [DllImport("user32.dll", EntryPoint = "GetKeyboardState")]
        public static extern int GetKeyboardState(byte[] pbKeyState);
        private static byte[] bs = new byte[256];
        /// <summary>
        /// 大小写键
        /// </summary>
        public static bool CapsLockStatus
        {
            get
            {
                GetKeyboardState(bs);
                return (bs[0x14] == 1);
            }
        }
 

        [DllImport("user32.dll", EntryPoint = "SendMessage")]
        public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
 
 
        public const Int32 KEYEVENTF_KEYDOWN = 0;
        public const Int32 KEYEVENTF_KEYUP = 2;
 
    }
}
